package com.qinghuan.designMode.prePrinciple.Demeter;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: qinghuan
 * @Date: 2022/2/21 20:34
 * @Description:迪米特原则（只与直接的朋友通信） 最少知道原则
 * 1、一个对象应该 对其他对象保持最少了解
 * 2、类与类关系越密切，耦合度越大
 * ★3、每个对象都会与其他对象有耦合关系，只要两个对象之前有耦合关系，我们就说这两个对象之间是朋友关系。
 * ★★★★★出现 成员变量、方法参数、方法返回值中的类为直接的朋友
 */
public class Demeter1 {
    public static void main(String[] args) {
        SchoolManager schoolManager = new SchoolManager();
        schoolManager.PrintAllEmployee(new CollegeManager());
    }
}

//学校总部员工类
class Employee {
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

//学院的员工
class CollegeEmployee {
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

class CollegeManager {
    public List<CollegeEmployee> getAllEmployee() {
        List<CollegeEmployee> list = new ArrayList<CollegeEmployee>();
        for (int i = 0; i < 10; i++) {
            CollegeEmployee collegeEmployee = new CollegeEmployee();
            collegeEmployee.setId("学院员工id=" + i);
            list.add(collegeEmployee);
        }
        return list;
    }
}

//学校管理类
class SchoolManager {
    //返回学校总部的员工
    public List<Employee> getAllEmployee() {
        List<Employee> list = new ArrayList<Employee>();
        for (int i = 0; i < 5; i++) {
            Employee employee = new Employee();
            employee.setId("学校总部员工id=" + i);
            list.add(employee);
        }
        return list;
    }

    void PrintAllEmployee(CollegeManager sub) {
        List<CollegeEmployee> list1 = sub.getAllEmployee();
        System.out.println("--------学院员工----------");
        for (CollegeEmployee e : list1) {
            System.out.println(e.getId());
        }
        List<Employee> list2 = this.getAllEmployee();
        System.out.println("--------学校总部员工----------");
        for (Employee e : list2) {
            System.out.println(e.getId());
        }
    }
}
